#!/bin/bash
assert() {
    target="$1"
    targetcc="$1cc"
    expected="$2"
    input="$3"

    ./$target "$input" > "$target.s"
    cc -o "$targetcc" "$target.s"
    ./$targetcc
    actual="$?"

    if [ "$actual" = "$expected" ]; then
        echo "$input => $actual"
    else
        echo "$input => $expected expected, but got $actual"
        exit 1
    fi
}

# make first
make
if [ "$?" = "0" ]
then
    echo "make succ"
else
    echo "make failed"
    exit 1
fi

# start test
add_sub="add_sub"

assert $add_sub 21 "5+20-4"